package com.vcredit.creditcat.service;
import com.vcredit.creditcat.model.BankInfo;
import com.vcredit.creditcat.persistence.base.BankInfoMapper;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
/**
 * 
 **/
@Service
public class BankInfoService {
	@Autowired
    private BankInfoMapper mapper;
    
	@CacheEvict(key = "'BankInfo'", value = "default")
    public void insert(BankInfo obj){
    	mapper.insert(obj);
    }
    
    @CacheEvict(key = "'BankInfo'", value = "default")
    public void update(BankInfo obj){
    	mapper.update(obj);
    }
    
    public List<BankInfo> findAll(){
		return mapper.findAll();
	}
    
    @Cacheable(key = "'BankInfo'", value = "default")
    public Map<String,BankInfo> findAllForMap() {
    	List<BankInfo> all = this.findAll();
    	Map<String,BankInfo> result = new HashMap<String,BankInfo>();
    	for (BankInfo bankInfo : all) {
    		result.put(bankInfo.getBankCode(), bankInfo);
		}
    	return result;
    }
	
	private List<BankInfo> find(BankInfo obj){
		return mapper.find(obj);
	}
}